<?php
//	require_once("fpdf/fpdf.php");
	require_once("tfpdf/tfpdf.php");
	class PDF extends tFPDF
	{
	// Colored table
		function FancyTable($header, $data)
		{
			// Colors, line width and bold font
			$this->SetFillColor(57,242,140);
			$this->SetTextColor(13,40,230);
			$this->SetDrawColor(128,0,0);
			$this->SetLineWidth(.1);

			$this->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
			$this->SetFont('DejaVu','',12);
			// Header
			$this->Ln(15);
			
			$w = array(20, 30, 30, 40, 40, 29);
			for($i=0;$i<count($header);$i++)
				$this->Cell($w[$i],10,$header[$i],1,0,'C',true);
			$this->Ln();
			// Color and font restoration
			$this->SetFillColor(224,235,255);
			$this->SetTextColor(0);
			$this->SetFont('');
			// Data
			$fill = false;
			
			$arr = explode("-",$data);
			$cnt = count($arr);
			$stt = 1;
			for($i=0 ; $i < $cnt-1 ; $i++)
			{	
				$arr_col = explode(",",$arr[$i]);
				$this->Cell($w[0],10,$stt,'LRTB',0,'C',$fill);
				$this->Cell($w[1],10,'Tuần '.$arr_col[0],'LRTB',0,'C',$fill);
				$this->Cell($w[2],10,$arr_col[1],'LRTB',0,'C',$fill);
				$this->Cell($w[3],10,$arr_col[2],'LRTB',0,'C',$fill);
				$this->Cell($w[4],10,$arr_col[3],'LRTB',0,'C',$fill);
				$this->Cell($w[5],10,$arr_col[4],'LRTB',0,'C',$fill);
				$this->Ln();	
				$stt++;
				$fill = !$fill;
			}
			// Closing line
			$this->Cell(array_sum($w),0,'','T');
			
		} // end function fancy table
		
		function Table_diemdanh($header, $data, $sb)
		{
			// Colors, line width and bold font
			$this->SetFillColor(57,242,140);
			$this->SetTextColor(13,40,230);
			$this->SetDrawColor(128,0,0);
			$this->SetLineWidth(.1);

			$this->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
			$this->SetFont('DejaVu','',12);
			// Header
			$this->Ln(10);
			
			$w = array(10, 25, 45);
			for($i=1 ; $i<=$sb ; $i++)
			 	array_push($w,27);
			array_push($w,20);
				
			for($i=0;$i<count($header);$i++)
				$this->Cell($w[$i],10,$header[$i],1,0,'C',true);
				
			$this->Ln();
			// Color and font restoration
			$this->SetFillColor(224,235,255);
			$this->SetTextColor(0);
			$this->SetFont('');
			// Data
			$fill = false;
			
			$arr = explode("+",$data);
			$cnt = count($arr);
			$stt = 1;
			for($i=0 ; $i<$cnt-1 ; $i++)
			{	
				$arr_col = explode(",",$arr[$i]);
				$mx = $arr_col[2];
				$this->Cell($w[0],10,$stt,'LRTB',0,'C',$fill);
				for($j=1;$j<=2;$j++)
					$this->Cell($w[$j],10,$arr_col[$j-1],'LRTB',0,'C',$fill);	
					
				for($j=3;$j<count($header)-1;$j++)
				{
					$k = $j - 2;	$d = explode("t",$arr_col[3]);
					if($mx >= $k)
						$this->Cell($w[$j],10,$d[$k-1],'LRTB',0,'C',$fill);	
					else
						$this->Cell($w[$j],10,'','LRTB',0,'C',$fill);	
				}
				$col = count($header);
				$this->Cell($w[$col-1],10,$mx."/".$sb,'LRTB',0,'C',$fill);
				$this->Ln();
				$stt++;
				$fill = !$fill;
			}
			// Closing line
			$this->Cell(array_sum($w),0,'','T');
			
		} // end function table_diemdanh
		
		function Table8($header, $data)
		{
			// Colors, line width and bold font
			$this->SetFillColor(57,242,140);
			$this->SetTextColor(13,40,230);
			$this->SetDrawColor(128,0,0);
			$this->SetLineWidth(.1);

			$this->AddFont('DejaVu','','DejaVuSansCondensed.ttf',true);
			$this->SetFont('DejaVu','',11);
			// Header
			$this->Ln(10);
			
			$w = array(10, 15, 10, 25, 25, 15, 70, 20);
			for($i=0;$i<count($header);$i++)
				$this->Cell($w[$i],10,$header[$i],1,0,'C',true);
			$this->Ln();
			// Color and font restoration
			$this->SetFillColor(224,235,255);
			$this->SetTextColor(0);
			$this->SetFont('');
			// Data
			$fill = false;
			
			$arr = explode("+",$data);
			$cnt = count($arr);
			$stt = 1;
			for($i=0 ; $i < $cnt-1 ; $i++)
			{	
				$arr_col = explode(",",$arr[$i]);
				$this->Cell($w[0],10,$stt,'LRTB',0,'C',$fill);
				$this->Cell($w[1],10,'Tuần '.$arr_col[0],'LRTB',0,'C',$fill);
				$this->Cell($w[2],10,$arr_col[1],'LRTB',0,'C',$fill);
				$this->Cell($w[3],10,$arr_col[2],'LRTB',0,'C',$fill);
				$this->Cell($w[4],10,$arr_col[3],'LRTB',0,'C',$fill);
				$this->Cell($w[5],10,$arr_col[4],'LRTB',0,'C',$fill);
				$this->Cell($w[6],10,$arr_col[5],'LRTB',0,'C',$fill);
				$this->Cell($w[7],10,$arr_col[6],'LRTB',0,'C',$fill);
				$this->Ln();	
				$stt++;
				$fill = !$fill;
			}
			// Closing line
			$this->Cell(array_sum($w),0,'','T');
			
		} // end function fancy table 8

		// function header		
		/*function Header()
		{
			global $title;
		
			 Arial bold 15
			$this->SetFont('Arial','B',15);
			 Calculate width of title and position
			$w = $this->GetStringWidth($title)+6;
			$this->SetX((210-$w)/2);
			 Colors of frame, background and text
			$this->SetDrawColor(0,80,180);
			$this->SetFillColor(255,255,255);
			$this->SetTextColor(220,50,50);
			 Thickness of frame (1 mm)
			$this->SetLineWidth(0);
			 Title
			$this->Cell($w,9,$title,1,1,'C',true);
			 Line break
			$this->Ln(10);
		}*/
		
		// function footer
		function Footer()
		{
			// Position at 1.5 cm from bottom
			$this->SetY(-15);
			// Arial italic 8
			$this->SetFont('Arial','I',8);
			// Text color in gray
			$this->SetTextColor(128);
			// Page number
			$this->Cell(0,10,'Trang '.$this->PageNo(),0,0,'C');
		}
		
		// function chapter
		function ChapterTitle($num, $label)
		{
			// Arial 12
			$this->SetFont('Arial','',12);
			// Background color
			$this->SetFillColor(200,220,255);
			// Title
			$this->Cell(0,6,"Chapter $num : $label",0,1,'L',true);
			// Line break
			$this->Ln(4);
		}
		
		// function chapBody
		function ChapterBody($file)
		{
			// Read text file
			$txt = file_get_contents($file);
			// Times 12
			$this->SetFont('Times','',12);
			// Output justified text
			$this->MultiCell(0,5,$txt);
			// Line break
			$this->Ln();
			// Mention in italics
			$this->SetFont('','I');
			$this->Cell(0,5,'(end of excerpt)');
		}
		
		
		// print chap
		function PrintChapter($num, $title, $file)
		{
			$this->AddPage();
			$this->ChapterTitle($num,$title);
			$this->ChapterBody($file);
		}
		
		
		
		
	} // end class

?>